#include <iostream>
#include "sqlist.h"

using namespace std;

Status HeapSort(SqList &);
void MaxHeapify(SqList &, int, int);

int main(void)
{
	SqList sql;
	sql.InitList();
	int num[10], i;
	for(i = 0; i <= 9; i++)
		cin >> num[i];
	for(i = 0; i <= 9; i++)
		sql.ListInsert(num[i]);
	HeapSort(sql);
	for(i = 1; i <= 10; i++)
		printf("%d ", sql.GetElem(i));
	return 0;
}

Status HeapSort(SqList &L)
{
	int len = L.length-1;
	ElemType temp;
	for(int i = len/2; i >= 0; i--)
		MaxHeapify(L, i, len);
	for(int i = len; i >= 0; i--)
	{
		temp = L.elem[0];
		L.elem[0] = L.elem[i];
		L.elem[i] = temp;
		MaxHeapify(L, 0, i);
	}
	return OK;
}

void MaxHeapify(SqList &L, int i, int len)
{
	int left = 2*i+1, right = 2*i+2, max;
	ElemType temp;
	max = i;
	if(left < len && L.elem[left] > L.elem[max])
		max = left;
	if(right < len && L.elem[right] > L.elem[max])
		max = right;
	if(max != i)
	{
		temp = L.elem[i];
		L.elem[i] = L.elem[max];
		L.elem[max] = temp;
		MaxHeapify(L, max, len);
	}
}
